home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / lzw4c11.zip / UN_ARC.C < prev    next >
Text File  |  1992-11-08  |  2KB  |  92 lines

  1. /*
  2. **   UN_ARC.C       Copyright (C) 1992 by MarshallSoft Computing, Inc.
  3. **
  4. **   This program is used to expand archive created with MK_ARC. For
  5. **   example, to un-archive all the files in 'C.ARF', type:
  6. **
  7. **      UN_ARC C.ARF
  8. */
  9.  
  10. #include <stdio.h>
  11. #include <dos.h>
  12. #include <fcntl.h>
  13. #include <sys\types.h>
  14. #include <sys\stat.h>
  15. #include <io.h>
  16.  
  17. #include "LZW4C.H"
  18. #include "RW_IO.H"
  19. #include "DIR_IO.H"
  20.  
  21. extern char *malloc();
  22. extern int free();
  23.  
  24. void SayError(int);
  25.  
  26. void main(argc,argv)
  27. int argc;
  28. char *argv[];
  29. {int i, k, c;
  30.  int RetCode;
  31.  char Filename[15];
  32.  int Files = 0;
  33.  /* begin */
  34.  if(argc!=2)
  35.    {printf("Usage: UN_ARC <archive_filespec>\n");
  36.     exit(1);
  37.    }
  38.  RetCode = InitLZW(malloc);
  39.  if(RetCode<0)
  40.    {SayError(RetCode);
  41.     exit(2);
  42.    }
  43.  puts("\nUN_ARC 1.0: Type any key to abort...");
  44.  /* open input file for expansion */
  45.  if(!ReaderOpen(argv[1])) exit(4);
  46.  for(i=0;;i++)
  47.    {if(kbhit())
  48.       {puts("\n...Aborted by user !");
  49.        break;
  50.       }
  51.     /* get filename */
  52.     for(k=0;k<5;k++)
  53.        {c = Reader();
  54.         if(c==-1)
  55.            {ReaderClose();
  56.             TermLZW(free);
  57.             printf("\n%d files expanded\n",Files);
  58.             exit(0);
  59.            }
  60.         /* skip past any 0's */
  61.         if(c!='\0') break;
  62.        }
  63.     Filename[0] = (char)c;
  64.     for(k=1;k<13;k++)
  65.        {c = Reader();
  66.         Filename[k] = (char)c;
  67.         if(c=='\0') break;
  68.        }
  69.     if(c!='\0')
  70.        {printf("ERROR: Cannot find filename in %s\n",argv[1]);
  71.         TermLZW(free);
  72.         exit(0);
  73.        }
  74.     if(strcmp(Filename,argv[1])==0)
  75.       {printf("ERROR: Archive contains file '%s' named same as archive\n",argv[1]);
  76.        exit(1);
  77.       }
  78.     else
  79.       {/* open output file */
  80.        printf("Expanding %12s ",Filename);
  81.        if(!WriterOpen(Filename)) exit(3);
  82.        /* do the expansion */
  83.        Files++;
  84.        if((RetCode=Expand(Reader,Writer))<0)
  85.          {SayError(RetCode);
  86.           exit(5);
  87.          }
  88.        puts("OK");
  89.        WriterClose();
  90.       }
  91.    }
  92. }